#! /bin/perl

$pwd = @ARGV[0];
$home = @ARGV[1];
$software= "$home/bin/software";
print("$software\n");
system("sudo -S pacman -Syy<<EOF\n$pwd\nEOF");
`sudo -k`;
system("sudo -S pacman -S pacman -S fcitx5-chinese-addons fcitx5-gtk fcitx5-qt fcitx5-pinyin-zhwiki kcm-fcitx5<<EOF\n$pwd\ny\nEOF");
`sudo -k`;
system("sudo -S pacman -S pacman -S wqy-microhei wqy-zenhei wqy-bitmapfont ttf-arphic-uming<<EOF\n$pwd\ny\nEOF");
`sudo -k`;
system("sudo -S pacman -S feh code python-virtualenv rustup cmake clang llvm jdk11-openjdk dmenu sakura nodejs wmname firefox<<EOF\n$pwd\ny\nEOF");
`sudo -k`;
system("sudo -S pacman -S slock  meld npm arandr scrot nginx unzip htop gftp gedit thunar make nasm ctags opera<<EOF\n$pwd\ny\nEOF");
system("mkdir -p $software");
`sudo -k`;
system("sudo -S pacman -S archlinuxcn-keyring<<EOF\n$pwd\ny\nEOF");
`sudo -k`;
system("sudo -S sed -i 's#SigLevel = Optional TrustAll##g' /etc/pacman.conf <<EOF\n$pwd\nEOF")
`sudo -k`;
system("sudo -S pacman -S yay copyq postman<<EOF\n$pwd\ny\nEOF");
system("yay -S wps-office-cn")
#配置git
`git config --global http.sslVerify false`;
`git config --global http.postBuffer 524288000`;
`git config --global core.editor vim`;
`git config --global merge.tool meld`;
`git config --global merge.conflictstyle diff3`;
`cat>>~/.gitconfig<<EOF\n[mergetool "meld"]\n cmd = meld \$LOCAL \$BASE \$REMOTE --output=\$MERGED --auto-merge\nEOF`;
`cat>>~/bin/meld.sh<<EOF\n#!/bin/sh\nmeld \$2 \$5\nEOF`;
`sudo -k`;
system("sudo -S chmod u+x ~/bin/meld.sh<<EOF\n$pwd\nEOF");
`git config --global diff.external ~/bin/meld.sh`;
#system("cd $software;curl -s http://iproject.gitee.io/isoftware/archlinux/dwm.sh | bash");
`cd $software;curl -O https://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/8601a18b87d6277f9f0b14032a381f30e924fceb.jpg`;
`echo "\n" > ~/.xinitrc`;
`sed -i '2iexport INPUT_METHOD="fcitx5"' ~/.xinitrc`;
`sed -i '3iexport GTK_IM_METHOD="fcitx5"' ~/.xinitrc`;
`sed -i '4iexport QT_IM_METHOD="fcitx5"' ~/.xinitrc`;
`sed -i '5iexport XMODIFIERS="@im=fcitx5"' ~/.xinitrc`;
`sed -i '6ifcitx5 -d' ~/.xinitrc`;
`sed -i '7ifeh --bg-fill --no-fehbg -z \$HOME/bin/software/8601a18b87d6277f9f0b14032a381f30e924fceb.jpg' ~/.xinitrc`;
`sed -i '8iwhile true;do' ~/.xinitrc`;
`sed -i '9i xsetroot -name "\$( date +"%Y-%m-%d %H:%M:%S" )' ~/.xinitrc`;
`sed -i '10isleep 1s' ~/.xinitrc`;
`sed -i '11idone' ~/.xinitrc`;
`sed -i '12iexport PATH=\$HOME/bin:\$PATH' ~/.xinitrc`;
`sed -i '13iwmname LG3D' ~/.xinitrc`;
`sed -i '14iexec dwm' ~/.xinitrc`;

#system("cd $software;wget -c http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/2021-06/R/eclipse-jee-2021-06-R-linux-gtk-x86_64.tar.gz");
#system("cd $software;tar xvf eclipse-jee-2021-06-R-linux-gtk-x86_64.tar.gz");
#system("cd $software;wget -c https://builds.garudalinux.org/repos/chaotic-aur/x86_64/peazip-qt5-8.2.0-1-x86_64.pkg.tar.zst");
#`sudo -k`;
#system("cd $software;sudo -S pacman -U ./peazip-qt5-8.2.0-1-x86_64.pkg.tar.zst <<EOF\n$pwd\ny\nEOF");
#system("cd $software;wget -c https://downloads.gradle-dn.com/distributions/gradle-6.7.1-bin.zip;unzip ./gradle-6.7.1-bin.zip");
#system("cd $software;wget -c https://dlcdn.apache.org/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.zip;unzip ./apache-maven-3.8.2-bin.zip");
#system("cd $software;wget -c https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/linux/OpenJDK8U-jdk_x64_linux_hotspot_8u302b08.tar.gz;tar xvf OpenJDK8U-jdk_x64_linux_hotspot_8u302b08.tar.gz");
system("curl -s  https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh | sed s/github/gitee/g | sed s#ohmyzsh/ohmyzsh#mirrors/oh-my-zsh#g | sh");
`sed -i s/robbyrussell/ys/g ~/.zshrc`;
system("chsh -s /bin/zsh <<EOF\n$pwd\nEOF");
`ln -s $home/bin/software/gradle-6.7.1/bin/gradle $home/bin`;
#`ln -s $home/bin/software/apache-maven-3.8.2/bin/mvn $home/bin`;
#`ln -s $home/bin/software/eclipse/eclipse $home/bin`;
system("npm config set registry http://registry.npmjs.org/");
system("npm config get registry");
`cat>>~/.vimrc<<EOF\nset number\nsyntax on\nset showmode\nset showcmd\nset number\nEOF`;
`cat>>~/.vimrc<<EOF\nsyntax on\nset showmode\nset showcmd\nset encoding=utf-8\nEOF`;
`cat>>~/.vimrc<<EOF\nset t_Co=256\nfiletype indent on\nset tabstop=2\nset shiftwidth=4\nEOF`;
`cat>>~/.vimrc<<EOF\nset expandtab\nset softtabstop=2\nset cursorline\nset textwidth=100\nEOF`;
`cat>>~/.vimrc<<EOF\nset wrap\nset linebreak\nset wrapmargin=2\nset laststatus=2\nset ruler\nEOF`;
`cat>>~/.vimrc<<EOF\nset nobackup\nset noswapfile\nset undofile\nset noerrorbells\nset history=1000\nEOF`;
`cat>>~/.vimrc<<EOF\nset wildmenu\nset wildmode=longest:list,full\nset backupdir=~/.vim/.backup//\nEOF`;
`cat>>~/.vimrc<<EOF\nset directory=~/.vim/.swp//\nset undodir=~/.vim/.undo//\nEOF`;
